package com.dytj.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.dytj.pojo.Movie;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class MovieDao {
	
	public static List<Movie> selectMovie() throws SQLException {
		List<Movie> list = new ArrayList<Movie>();
		Connection conn = (Connection) DBUtil.getConn();
		Statement st = (Statement) conn.createStatement();
		//sql处理
		String sql = "select * from movie";
		ResultSet rs = st.executeQuery(sql);
		while(rs.next()){
			Movie movie = new Movie();
			movie.setCategoryId(rs.getInt("category_id"));
			movie.setDirector(rs.getString("director"));
			movie.setImage(rs.getString("image"));
			movie.setIntroduction(rs.getString("introduction"));
			movie.setMovieId(rs.getInt("movie_id"));
			movie.setName(rs.getString("name"));
			movie.setReleaseDate(rs.getString("release_date"));
			movie.setScreenwriter(rs.getString("screenwriter"));
			movie.setStyle(rs.getString("style"));
			list.add(movie);
		}
		rs.close();
		st.close();
		conn.close();
		return list;
	}
	
	public static List<Movie> selectName(Movie value) throws SQLException {
		List<Movie> list = new ArrayList<Movie>();
		Connection conn = (Connection) DBUtil.getConn();
		Statement st = (Statement) conn.createStatement();
		//sql处理
		String sql = "select * from movie";
		ResultSet rs = st.executeQuery(sql);
		while(rs.next()){
			Movie movie = new Movie();
			movie.setCategoryId(rs.getInt("category_id"));
			movie.setDirector(rs.getString("director"));
			movie.setImage(rs.getString("image"));
			movie.setIntroduction(rs.getString("introduction"));
			movie.setMovieId(rs.getInt("movie_id"));
			movie.setName(rs.getString("name"));
			movie.setReleaseDate(rs.getString("release_date"));
			movie.setScreenwriter(rs.getString("screenwriter"));
			movie.setStyle(rs.getString("style"));
			list.add(movie);
		}
		rs.close();
		st.close();
		conn.close();
		return list;
	}
	
}
